#include<bits/stdc++.h>
using namespace std;
const int MAXN=100010,INF=1000000000;
struct treap
{
	int lc,rc,key,pri,siz,val;
}a[MAXN];
int n,m,ans,cnt,root,delta;
void push_up(int o)
{
	a[o].siz=a[a[o].lc].siz+a[a[o].rc].siz+a[o].val;
	return;
}
void lturn(int &o)
{
	int t=a[o].rc;
	a[o].rc=a[t].lc;
	a[t].lc=o;
	a[t].siz=a[o].siz;
	push_up(o);
	o=t;
	return;
}
void rturn(int &o)
{
	int t=a[o].lc;
	a[o].lc=a[t].rc;
	a[t].rc=o;
	a[t].siz=a[o].siz;
	push_up(o);
	o=t;
	return;
}
void insert(int &o,int k)
{
	if(!o)
	{
		o=++cnt;
		a[o]=(treap){0,0,k,rand(),1,1};
		return;
	}
	++a[o].siz;
	if(k==a[o].key)++a[o].val;
	else if(k>a[o].key)
	{
		insert(a[o].lc,k);
		if(a[a[o].lc].pri>a[o].pri)rturn(o);
	}
	else
	{
		insert(a[o].rc,k);
		if(a[a[o].rc].pri>a[o].pri)lturn(o);
	}
	return;
}
void del(int &o,int k)
{
	if(!o)return;
	if(k<=a[o].key)
	{
		del(a[o].rc,k);
		push_up(o);
	}
	else
	{
		ans+=a[a[o].rc].siz+a[o].val;
		a[o].rc=0;
		o=a[o].lc;
		del(o,k);
		push_up(o);
	}
	return;
}
int find(int o,int k)
{
	if(!o)return 0;
	if(k<=a[a[o].lc].siz)return find(a[o].lc,k);
	if(k<=a[a[o].lc].siz+a[o].val)return o;
	return find(a[o].rc,k-a[a[o].lc].siz-a[o].val);
}
int main()
{
	scanf("%d%d",&n,&m);
	srand(n);
	char t1[3];
	int t2;
	for(int i=1;i<=n;++i)
	{
		scanf("%s%d",t1,&t2);
		if(t1[0]=='I')
			if(t2>=m)insert(root,t2-delta);
		if(t1[0]=='A')delta+=t2;
		if(t1[0]=='S')
		{
			delta-=t2;
			del(root,m-delta);
		}
		if(t1[0]=='F')
		{
			t2=find(root,t2);
			if(!t2)printf("-1\n");
			else printf("%d\n",a[t2].key+delta);
		}
	}
	printf("%d\n",ans);
	return 0;
}
